import Vue from 'vue'
import VueRouter from 'vue-router'

import HomeView from '../views/HomeView.vue'
// import weclome from '../components/WelCome.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/homeone',
    name: 'homeone',
    redirect: 'weclome',
    component: () => import('../views/HomeOne.vue'),
    children:[
      {
        path:'/weclome',
        component: () => import('../components/WelCome.vue'),
      },
      {
        path:'/users',
        component: () =>import('../components/UsersOne.vue'),
      },
      {
         path:'/rights',
         component: () => import('../components/RightOne.vue'),
      },
      {
         path:'/roles',
         component: () => import('../components/RolesOne.vue')
      },
      {
         path:'/categories',
         component: () => import('../components/CategoriesOne.vue')
      },
      {
         path:'/params',
         component: () => import('../components/ParamsOne.vue')
      },
      {
         path:'/goods',
         component: () => import('../components/ListOne.vue')
      },
      {
         path:'/orders',
         component: () => import('../components/OrderOne.vue')
      }
   

    ]
  },

 {
  path: '/mylogin',
  name: 'mylogin',
  component: () => import('../views/MyLogin.vue'),
 },
  {
    path: '/',
    name: 'home',
    component: HomeView,
    // redirect:'/welcome',
    childred:[{
      // path:'welcome',
      // component:[{path:'/welcome',component:Welcome}]

    }]
  },
  {

    
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = new VueRouter({

  routes
})


// 挂载路由导航守卫
router.beforeEach((to,from,next) => {
  // to 将要访问的路劲
  // from 代表从哪个路径过来
  // next 是一个函数,表示放行
  if(to.path==='/mylogin') return next()
  // 获取token
  const token =window.sessionStorage.getItem('token')
  if(!token) return next('/mylogin')
  // 如果存在则直接放行
  next()
})
export default router
